<template>
  <div class="statisticalanalysis">
    <el-button @click="print" class="signs print" v-if="list.shStatus == 2"
      >打印</el-button
    >
    <el-tooltip
      class="item"
      effect="dark"
      content="审核通过才可以打印"
      v-else
      placement="top-start"
    >
      <el-button class="signs print" style="cursor: not-allowed"
        >打印</el-button
      >
    </el-tooltip>
    <div ref="print">
      <el-card class="box-card">
        <div style="width: 100%; text-align: center">
          <span
            style="
              height: 45px;
              display: inline-block;
              line-height: 45px;
              font-weight: 700;
            "
            >受限空间作业证</span
          >
        </div>
        <table border="1" cellspacing="0">
          <tr align="center" height="35px">
            <td>申请单位</td>
            <td width="16%">{{ list.sqdwmc }}</td>
            <td width="16%">申请人</td>
            <td colspan="2" width="16%">{{ list.sqrmc }}</td>
            <td width="16%">作业证编号</td>
            <td width="16%" colspan="2">{{ list.sqrq }}</td>
          </tr>
          <tr align="center" height="35px">
            <td>受限空间所属单位</td>
            <td>{{ list.zydwmc }}</td>
            <td colspan="3">受限空间名称</td>
            <td colspan="3">{{ list.sxkjmc }}</td>
          </tr>
          <tr align="center" height="35px">
            <td>作业内容</td>
            <td>{{ list.zynr }}</td>
            <td colspan="3">受限空间内原有介质名称</td>
            <td colspan="3">{{ list.sxkjnyyjzmc }}</td>
          </tr>
          <tr align="center" height="35px">
            <td colspan="1">作业时间</td>
            <td colspan="7" style="padding-right: 4rem">
              自<span>{{ list.zykssj }}</span> 始<span>{{ list.zyjssj }}</span
              >止
            </td>
          </tr>
          <tr align="center" height="35px">
            <td colspan="1">作业单位负责人</td>
            <td colspan="7">{{ list.zydwfzrmc }}</td>
          </tr>
          <tr align="center" height="35px">
            <td colspan="1">监护人</td>
            <td colspan="7">{{ list.jhrmc }}</td>
          </tr>
          <tr align="center" height="35px">
            <td colspan="1">作业人</td>
            <td colspan="7">{{ list.zyrmc }}</td>
          </tr>
          <tr align="center" height="35px">
            <td colspan="1">涉及的其他特殊作业</td>
            <td colspan="7">{{ list.sjdqttszy }}</td>
          </tr>
          <tr align="center" height="80px">
            <td colspan="1">危害辨识</td>
            <td colspan="7">{{ list.whbs }}</td>
          </tr>
          <!-- 分析 -->
          <tr align="center" height="35px">
            <td :rowspan="2 + fxsj.length + 1" colspan="1">分析</td>
            <td>分析项目</td>
            <td>有毒有害介质</td>
            <td>可燃气</td>
            <td>氧含量</td>
            <td rowspan="2">时间</td>
            <td rowspan="2">部位</td>
            <td rowspan="2">分析人</td>
          </tr>
          <tr align="center" height="35px">
            <td>分析标准</td>
            <td>{{ list.ydyhjz }}</td>
            <td>{{ list.krq }}</td>
            <td>{{ list.yhl }}</td>
          </tr>
          <tr align="center" height="0px">
            <td :rowspan="fxsj.length + 1">分析数据</td>
          </tr>
          <tr
            align="center"
            height="35px"
            v-for="(item, index) in fxsj"
            :key="index"
          >
            <td>{{ item.ydyhjz }}</td>
            <td>{{ item.krq }}</td>
            <td>{{ item.yhl }}</td>
            <td>{{ item.sj }}</td>
            <td>{{ item.bw }}</td>
            <td v-text="list.fxrmc"></td>
          </tr>
          <!-- 安全措施 -->
          <tr align="center" height="35px">
            <td>序号</td>
            <td colspan="6">安全措施</td>
            <td>确认人</td>
          </tr>
          <tr align="center" height="40px">
            <td>1</td>
            <td class="textleft" colspan="6">对进入受限空间危险性进行分析</td>
            <td>{{ list.aqcsqrrmc }}</td>
          </tr>
          <tr align="center" height="40px">
            <td>2</td>
            <td class="textleft" colspan="6">
              所有与受限空间有联系的阀门、管线加盲板隔离，列出盲板清单，并落实拆装盲板责任人
            </td>
            <td>{{ list.aqcsqrrmc }}</td>
          </tr>
          <tr align="center" height="40px">
            <td>3</td>
            <td class="textleft" colspan="6">设备经过置换、吹扫、蒸煮</td>
            <td>{{ list.aqcsqrrmc }}</td>
          </tr>
          <tr align="center" height="40px">
            <td>4</td>
            <td class="textleft" colspan="6">
              设备打开通风孔进行自然通风，温度适宜人员作业；必要时采用强制通风或佩戴空气呼吸器，不能用通氧气或富氧空气的的方法补充氧
            </td>
            <td>{{ list.aqcsqrrmc }}</td>
          </tr>
          <tr align="center" height="40px">
            <td>5</td>
            <td class="textleft" colspan="6">
              相关设备进行处理，带搅拌机的设备应切断电源，电源开关处加锁或挂“禁止合闸”标志牌，设专人监护
            </td>
            <td>{{ list.aqcsqrrmc }}</td>
          </tr>
          <tr align="center" height="40px">
            <td>6</td>
            <td class="textleft" colspan="6">
              检查受限空间内部已具备作业条件，清罐时（无需要/已采用）防爆工具
            </td>
            <td>{{ list.aqcsqrrmc }}</td>
          </tr>
          <tr align="center" height="40px">
            <td>7</td>
            <td class="textleft" colspan="6">
              检查受限空间进出口通道，无阻碍人员进出的障碍物
            </td>
            <td>{{ list.aqcsqrrmc }}</td>
          </tr>
          <tr align="center" height="40px">
            <td>8</td>
            <td class="textleft" colspan="6">
              分析盛装过可燃有毒液体、气体的受限空间内的可燃、有毒有害气体含量
            </td>
            <td>{{ list.aqcsqrrmc }}</td>
          </tr>
          <tr align="center" height="40px">
            <td>9</td>
            <td class="textleft" colspan="6">
              作业人员清楚受限空间内存在的其他危害因素，如内部附件、集渣坑等
            </td>
            <td>{{ list.aqcsqrrmc }}</td>
          </tr>
          <tr align="center" height="40px">
            <td>10</td>
            <td class="textleft" colspan="6">
              作业监护措施：消防器材（ ）、救生绳（ ）、气防装备（ ）
            </td>
            <td>{{ list.aqcsqrrmc }}</td>
          </tr>
          <tr align="center" height="80px">
            <td>11</td>
            <td colspan="6" class="postion">
              <span class="safetymeasures"
                >其他安全措施：{{ list.qtaqcs }}</span
              >
              <span class="makePeopleTwo">编制人：{{ list.qtaqcsbzrmc }}</span>
            </td>
            <td>{{ list.qtaqcsqrrmc }}</td>
          </tr>

          <tr align="center" height="40px">
            <td>实施安全教育</td>
            <td colspan="2">{{ list.ssaqjyrmc }}</td>
            <td colspan="2"></td>
            <td colspan="3"></td>
          </tr>
          <tr height="60px">
            <td colspan="13" style="border-bottom: none; padding-left: 10px">
              申请单位意见：{{ list.sqdwyj }}
            </td>
          </tr>
          <tr height="60px">
            <td
              align="right"
              colspan="13"
              style="border-top: none; padding-right: 2rem"
            >
              签字：{{ list.sqdwqzmc }}
              <span style="padding-left: 1rem">{{ list.sqdwqzrq }}</span>
            </td>
          </tr>
          <tr height="60px">
            <td colspan="13" style="border-bottom: none; padding-left: 10px">
              审批单位意见：{{ list.spdwyj }}
            </td>
          </tr>
          <tr height="60px">
            <td
              align="right"
              colspan="13"
              style="border-top: none; padding-right: 2rem"
            >
              签字：{{ list.spbmqzmc }}
              <span style="padding-left: 1rem">{{ list.sprq }}</span>
            </td>
          </tr>
          <tr height="60px">
            <td colspan="13" style="border-bottom: none; padding-left: 10px">
              完工验收：{{ list.wgys }}
            </td>
          </tr>
          <tr height="60px">
            <td
              align="right"
              colspan="13"
              style="border-top: none; padding-right: 2rem"
            >
              签字：{{ list.wgysqzmc }}
              <span style="padding-left: 1rem">{{ list.wgysrq }}</span>
            </td>
          </tr>
        </table>
      </el-card>
    </div>
  </div>
</template>

<script>
import printStyle from "./printStyle";
import { previewDataInterface } from "@/api/systemData/dataInterface";

export default {
  props: {
    list: {
      type: Object,
      default: {},
    },
  },
  name: "shouxian",
  data() {
    return {
      fxsj: [],
    };
  },
  created() {
    this.fxsj = JSON.parse(this.list.fxsj);
    this.list.sqrq = this.formatDate(this.list.sqrq); //
    this.list.zykssj = this.formatDateH(this.list.zykssj); //
    this.list.zyjssj = this.formatDateH(this.list.zyjssj); //
    this.list.sqdwqzrq = this.formatDateH(this.list.sqdwqzrq); //
    this.list.sprq = this.formatDateH(this.list.sprq); //
    this.list.wgysrq = this.formatDateH(this.list.wgysrq); //
    // this.fxsjcl();
    this.getRYOptions();
    this.fxsj.forEach((item) => {
      if (item.sj) {
        item.sj = this.formatDate(item.sj);
      }
    });
  },
  methods: {
    formatDate(needTime) {
      //needTime是整数，否则要parseInt转换
      if (needTime !== null && needTime !== undefined) {
        var time = new Date(needTime);
        var y = time.getFullYear();
        var m = time.getMonth() + 1;
        var d = time.getDate();
        var h = time.getHours();
        var mm = time.getMinutes();
        return y + "年" + this.add0(m) + "月" + this.add0(d) + "日";
      } else {
        return "  年  月  日";
      }
    },
    formatDateH(needTime){
      //needTime是整数，否则要parseInt转换
        if(needTime !== null && needTime !== undefined){
          var time = new Date(needTime);
          var y = time.getFullYear();
          var m = time.getMonth()+1;
          var d = time.getDate();
          var h = time.getHours();
          var mm = time.getMinutes();
          // var s = time.getSeconds();
          return y+'年'+this.add0(m)+'月'+this.add0(d)+'日'+this.add0(h)+'时'+this.add0(mm)+'分';
        }else{
          return '  年  月  日  时  分';
        }
    },
    add0(m) {
      return m < 10 ? "0" + m : m;
    },
    // 打印
    print() {
      let print = this.$refs.print.innerHTML;
      let printPart = print + printStyle;
      let newTab = window.open("_blank");
      newTab.document.body.innerHTML = printPart;
      newTab.print();
      newTab.close();
    },
    getRYOptions() {
      previewDataInterface("8bca424f16d6448ab09e57a028853aa9").then((res) => {
        this.RYOptions = res.data;
        this.fxsj.forEach((item) => {
          if (item.fxr) {
            this.RYOptions.forEach((key) => {
              if (item.fxr == key.F_Id) {
                item.fxrmc = key.F_RealName;
              }
            });
          }
        });
        // for(let i in this.fxsj){
        //   if(this.fxsj[i].fxr){
        //     for(let r in this.RYOptions){
        //       if(this.fxsj[i].fxr == this.RYOptions[r].F_Id){
        //         this.fxsj[i].fxrmc = this.RYOptions[r].F_RealName;
        //       }
        //     }
        //   }
        // }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.statisticalanalysis {
  .signs {
    position: absolute;
    right: 10px;
    top: 70px;
    &.print {
      top: 20px;
      right: 50px;
    }
  }
  .postion {
    position: relative;
    .safetymeasures {
      position: absolute;
      left: 20px;
      top: 10px;
    }
    .makePeopleTwo {
      position: absolute;
      left: 440px;
      top: 50px;
    }
  }
  .signs {
    position: absolute;
    right: 10px;
    top: 70px;
    &.print {
      top: 20px;
      right: 50px;
    }
  }
  .box-card {
    width: 80%;
    margin: 0 auto;
    background: #fff;
    color: #606266;
    position: relative;
    table {
      margin: 0 auto;
      tr {
        .textleft {
          text-align: left;
          padding-left: 20px;
        }
      }
      span {
        display: inline-block;
        min-width: 20px;
      }
    }
  }
}
</style>